package com.lazar.module1.subject1

object Drink{
   def  main(args: Array[String]): Unit ={
     val money = 100
     var total = 0
     var bottle = 0
      bottle = buybeer(money)
      printf("当前啤酒数量：%d\n",bottle)
      total = exchange(bottle,bottle,bottle)
      printf("总啤酒数量：%d\n",total)
   }

  def exchange(total: Int,bottle: Int,cap: Int): Int ={
      if (bottle/3==0 && cap / 5 == 0){
         return total
      }
      // 空瓶换啤酒
      val beer = exchangeByBottle(bottle)
      // 总啤酒数量增加
      //total + beer
     // bottle + beer
      //cap + beer
      // 瓶盖换啤酒
      val beer2 = exchangeByCap(cap)
     //total + beer2
     //bottle + beer2
     //cap + beer2
     exchange(total+beer+beer2,beer+beer2,beer+beer2)
  }

  def buybeer(int: Int) :Int = {
    int / 2
  }

  def exchangeByBottle(bottle:Int):Int={
     bottle / 3
  }

  def exchangeByCap(cap:Int): Int ={
      cap / 5
  }
}


